require "net/http"
if ARGV.length < 1
	puts "Usage:ruby fetch_group_user.rb [dest_dir]"
	return
end

dest_dir = ARGV[0]
# TODO check dest_dir really exists
groups={
	"WMGD" => 1476,
	"214921" => 824,
	"197226" => 1122
}


url_regex=/(http:\/\/www.douban.com\/people\/.*?\/)/

groups.each do |key,value|
	
	puts "start fetch #{key}"

	f=open("#{dest_dir}/group_user_list_#{key}.txt",'w')
	value.times { |i|
		Net::HTTP.get(URI.parse("http://www.douban.com/group/#{key}/members?start=#{i*35}")).scan(url_regex){ |m| 
			puts m[0]
			f.puts(m[0])
		}
	
		sleep 15 
	}
	f.close

	puts "end fetch #{key}"

end
